﻿#region File and License Information
/*
<File>
	<License>
		Copyright © 2009 - 2017, Daniel Vaughan. All rights reserved.
		This file is part of Calcium (http://calciumsdk.net), 
		which is released under the MIT License.
		See file /Documentation/License.txt for details.
	</License>
	<CreationDate>2010-02-07 17:09:48Z</CreationDate>
</File>
*/
#endregion

using System;

namespace Outcoder.TaskModel
{
	/// <summary>
	/// Represents a <see cref="ITask"/> that is provided with an action 
	/// to be executed when the task is performed.
	/// </summary>
	/// <typeparam name="T">The type of argument provided 
	/// when the task is performed.</typeparam>
	public sealed class DelegateTask<T> : TaskBase<T>
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="DelegateTask{T}"/> class.
		/// </summary>
		/// <param name="execute">The execution handler. 
		/// This will be invoked when the task is performed.</param>
		/// <param name="descriptionForUser">The description for the user.</param>
		public DelegateTask(Action<TaskEventArgs<T>> execute, string descriptionForUser)
		{
			ArgumentValidator.AssertNotNull(execute, "execute");
			ArgumentValidator.AssertNotNullOrEmpty(descriptionForUser, "descriptionForUser");
			this.descriptionForUser = descriptionForUser;
			Execute += (o, args) => execute(args);
		}

		readonly string descriptionForUser;

		public override string DescriptionForUser
		{
			get
			{
				return descriptionForUser;
			}
		}

		public new bool Repeatable
		{
			get
			{
				return base.Repeatable;
			}
			set
			{
				base.Repeatable = value;
			}
		}
	}
}
